// Copyright 2022-2024 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef _USER_MAIN_H_
#define _USER_MAIN_H_

#ifdef __XC__

#include "i2c.h"
#include <platform.h>
#include <xk_audio_316_mc_ab/board.h>

extern unsafe client interface i2c_master_if i_i2c_client;
extern void board_setup();
extern void write_to_flash(void);
void key_driver(chanend c_eq);

extern unsafe chanend uc_i2s;
void i2s_driver(chanend c, chanend c_eq);

#define USER_MAIN_DECLARATIONS \
    interface i2c_master_if i2c[1];\
    chan c_i2s;\
    chan c_eq;

#define USER_MAIN_CORES on tile[0]: {\
                                        board_setup();\
                                        xk_audio_316_mc_ab_i2c_master(i2c);\
                                    }\
                        on tile[1]: {\
                                        unsafe\
                                        {\
                                            i_i2c_client = i2c[0]; \
                                            uc_i2s = (chanend) c_i2s;\
                                        }\
                                    }\
                        on tile[1]: {\
                                        i2s_driver(c_i2s, c_eq);\
                                    }\
                        on tile[0]: {\
                                        write_to_flash();\
                                        key_driver(c_eq);\
                                    }
                                    
#endif

#endif
